/***********************************
* sample_summary.do          *
***********************************/
use $data\allsample, clear
#delimit;
xtset sch_id;
capture drop sample2;
label var inc1 "HH income Less than 20K";
label var byfathed1 "Father Did not finish HS";
label var bymothed1 "Mother Did not finish HS";
label var Y "Complete 4-Yr College";


gen sample2 = sample;
replace sample2 = . if (T1==. & T2~=.) | (T1~=. & T2==.);  
replace sample2 = . if T1~=. & T2~=. & sample2==0;


local tc bytxrstd bytxmstd f1rgp9;
eststo A: estpost sum inc1 inc2 inc3 inc4 highincome byfathed1 byfathed2 byfathed3 byfathed4 bymothed1 bymothed2 bymothed3 bymothed4
cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 cbyrace6 f1rgp9 bytxrstd bytxmstd Y T1 T2 if sample==1
 ;
matrix b_A = e(mean);

eststo B: estpost sum inc1 inc2 inc3 inc4 highincome byfathed1 byfathed2 byfathed3 byfathed4 bymothed1 bymothed2 bymothed3 bymothed4
cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 cbyrace6 f1rgp9 bytxrstd bytxmstd Y T1 T2 if sample==0 & (T1==. & T2==.)
 ;
matrix b_B = e(mean); 
matrix b_C = J(25,1,0);
matrix b_t=J(25,1,0); 
matrix temp=J(2,1,0);

local col 1;
foreach var of var inc1 inc2 inc3 inc4 highincome byfathed1 byfathed2 byfathed3 byfathed4 bymothed1 bymothed2 bymothed3 bymothed4
cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 cbyrace6 f1rgp9 bytxrstd bytxmstd Y T1 T2 {;
xtreg `var' sample `tc' if sample2, fe;
matrix temp = e(b);
mat tempa = r(table);
mat b_t[`col',1]=tempa[4,1];
matrix b_C[`col',1]=temp[1,1];
local ++col;
};

matrix BB =[b_A',b_B',b_C, b_t];

local rows ;
foreach var of varlist inc1 inc2 inc3 inc4 highincome byfathed1 byfathed2 byfathed3 byfathed4 bymothed1 bymothed2 bymothed3 bymothed4
cbyrace1 cbyrace2 cbyrace3 cbyrace4 cbyrace5 cbyrace6 f1rgp9 bytxrstd bytxmstd Y T1 T2 {;
local this = strtoname("`: variable label `var''") ;
local rows `rows' `this';
};

mat rownames BB = `rows';
mat colnames BB = "In-Sample" "Out-Of-Sample" "Difference" "P-value";

mat li BB;

esttab matrix(BB, fmt(2 2 2 2)) using $tables\table_s3.tex, append title("Sample Comparison with GPA, Math and Reading scores, and School FE as controls");

